package handler

import (
	"github.com/gin-gonic/gin"
	"post-hub/internal/dto"
	"post-hub/internal/model"
	"post-hub/pkg"
	"post-hub/response"
)

func CreateComment(c *gin.Context) {

	var comment model.Comment
	err := c.ShouldBind(&comment)
	if err != nil {
		response.Error(c, "解析失败")
		return
	}
	token := c.Query("token")
	if token == "" {
		response.Error(c, "用户未登录")
	}
	comment = model.Comment{
		UserId:  comment.UserId,
		PostId:  comment.PostId,
		Content: comment.Content,
	}
	pkg.Comment()
	err = dto.CreateComment(&comment)
	if err != nil {
		response.Error(c, "发布失败")
		return
	} else {
		response.Success(c, "发布成功", comment.Content)
	}
}
